package team.hyznrj.studentsys.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import team.hyznrj.studentsys.exception.AuthenticationOnFlagException;
import team.hyznrj.studentsys.exception.DataBaseObjectNull;
import team.hyznrj.studentsys.exception.DataBaseObjectRefuse;
import team.hyznrj.studentsys.exception.DataBaseOperationError;
import team.hyznrj.studentsys.exception.DataIllegalException;
import team.hyznrj.studentsys.exception.DataNullException;
import team.hyznrj.studentsys.service.StudentMsgMapService;

@RestController
@RequestMapping("AcademyKeys")
@Api(value = "AcademyKeys")
public class StudentMsgMapController {
	@Autowired
	StudentMsgMapService service;
	/**
	 * 增加学院字段(需要传入flag)
	 * @param value
	 * @param necessary
	 * @param flag
	 * @return
	 * @throws DataNullException
	 * @throws DataBaseOperationError
	 * @throws AuthenticationOnFlagException
	 */
	@ResponseBody
	@RequestMapping(value="/addMsg",method={RequestMethod.POST} ,produces ="application/json;charset=utf-8")
	public Object addMsg(String value,boolean necessary,HttpServletRequest request) throws DataNullException, DataBaseOperationError, AuthenticationOnFlagException{
		String flag=(String) request.getAttribute("flag");
		return service.addMsg(value, necessary, flag);
	}
	/**
	 * 删除学院字段(需传入id)
	 * @param id
	 * @return
	 * @throws DataNullException
	 * @throws DataBaseOperationError
	 * @throws AuthenticationOnFlagException
	 * @throws DataBaseObjectNull
	 * @throws DataBaseObjectRefuse
	 */
	@ResponseBody
	@RequestMapping(value="/deleteMsg",method={RequestMethod.POST} ,produces ="application/json;charset=utf-8")
	public Object deleteMsg(String id) throws DataNullException, DataBaseOperationError, AuthenticationOnFlagException, DataBaseObjectNull, DataBaseObjectRefuse{
		return service.deleteMsg(id);
	}
	/**
	 * 更新学院字段(需传入id,value,necessary,flag)
	 * @param id
	 * @param value
	 * @param necessary
	 * @param flag
	 * @return
	 * @throws DataNullException
	 * @throws DataBaseOperationError
	 * @throws AuthenticationOnFlagException
	 * @throws DataBaseObjectNull
	 * @throws DataBaseObjectRefuse
	 * @throws DataIllegalException
	 */
	@ResponseBody
	@RequestMapping(value="/updateMsg",method={RequestMethod.POST} ,produces ="application/json;charset=utf-8")
	public Object updateMsg(String id,String value,boolean necessary,HttpServletRequest request) throws DataNullException, DataBaseOperationError, AuthenticationOnFlagException, DataBaseObjectNull, DataBaseObjectRefuse, DataIllegalException{
		String flag=(String) request.getAttribute("flag");
		return service.updateMsg(id, value, necessary,flag);
	}
	/**
	 * 获取全部学院字段
	 * @param flag
	 * @return
	 * @throws DataNullException
	 * @throws DataBaseOperationError
	 * @throws AuthenticationOnFlagException
	 * @throws DataBaseObjectNull
	 * @throws DataBaseObjectRefuse
	 * @throws DataIllegalException
	 */
	@ResponseBody
	@RequestMapping(value="/getAllMsg",method={RequestMethod.POST} ,produces ="application/json;charset=utf-8")
	public Object getAllMsg(HttpServletRequest request) throws DataNullException, DataBaseOperationError, AuthenticationOnFlagException, DataBaseObjectNull, DataBaseObjectRefuse, DataIllegalException{
		String flag=(String) request.getAttribute("flag");
		return service.getAllMsg(flag);
	}
	/**
	 * 获取单个字段(通过id)
	 * @param id
	 * @return
	 * @throws DataNullException
	 * @throws DataBaseOperationError
	 * @throws AuthenticationOnFlagException
	 * @throws DataBaseObjectNull
	 * @throws DataBaseObjectRefuse
	 * @throws DataIllegalException
	 */
	@ResponseBody
	@RequestMapping(value="/getMsgById",method={RequestMethod.POST} ,produces ="application/json;charset=utf-8")
	public Object getMsgById(String id) throws DataNullException, DataBaseOperationError, AuthenticationOnFlagException, DataBaseObjectNull, DataBaseObjectRefuse, DataIllegalException{
		return service.getMsgById(id);
	}
	
}
